package com.ninetaildemonfox.zdl.socialproject.mvp.presenter;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;

import com.google.gson.JsonObject;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.ninetaildemonfox.zdl.socialproject.config.Constants;
import com.ninetaildemonfox.zdl.socialproject.http.https.Model;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.PushSContract;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 创建人： Nine tails fox
 * 创建时间： 2019/8/8
 * 功能描述：
 * 联系方式：1037438704@qq.com
 *
 * @author NineTailDemonFox
 */

public class PushSettingsPresenter {
    public PushSContract pushSContract;
    public AppCompatActivity me;

    public PushSettingsPresenter(AppCompatActivity me) {
        this.me = me;
    }

    public PushSettingsPresenter(PushSContract pushSContract, AppCompatActivity me) {
        this.pushSContract = pushSContract;
        this.me = me;
    }

    public void setPush1(String token, String chat, String type) {
        Model.getInstance().getUserApi()
                .setPush1(token, chat, type)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null) {
                            return;
                        }
                        if (type.equals("1")) {
                            Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                            if (data == null) {
                                return;
                            }
                            pushSContract.Success(data);
                        } else {
                            ToastUtil.show(map.get("message"));
                        }
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {
                    }
                });
    }

    public void setPush2(String token, String new_yue) {
        Model.getInstance().getUserApi()
                .setPush2(token, new_yue)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null) {
                            return;
                        }
                        ToastUtil.show(map.get("message"));
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {
                    }
                });
    }
}
